/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servicios.Dao.Impl;

import Entidades.Cotizacion;
import Servicios.Dao.CotizacionDao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author TRACY
 */
public class CotizacionDaoImpl implements CotizacionDao{
    
    Connection cn;
    
    public CotizacionDaoImpl(Connection cn){
        this.cn = cn;
    }

    @Override
    public void createCotizacion(Cotizacion ct) {
       
        String sql = "INSERT INTO COTIZACION VALUES(?,?,?,?)";   
        Timestamp fecha1 = new Timestamp(ct.getFechaTraslado().getTime());
        Timestamp fecha2 = new Timestamp(ct.getFechaEmision().getTime());
        try {
            PreparedStatement pst = cn.prepareStatement(sql);
            pst.setString(1, ct.getIDCotizacion());
            pst.setString(2, ct.getIDSolicitud());
            pst.setTimestamp(3, fecha1);
            pst.setTimestamp(4, fecha2);
            pst.executeUpdate();
            pst.close();
        } catch (Exception ex) {
            System.out.println("error");
        }     
        
        
        
    }

    @Override
    public String calcularMaxIDSol() {
   
            String sql = "select MAX(IDCOTIZACION) maximo from COTIZACION";
        String max="";
        try {
            PreparedStatement pst = cn.prepareStatement(sql);
            ResultSet rs = pst.executeQuery();
            while (rs.next()) {                
                max = rs.getString("maximo");
            }
            pst.close();
        } catch (SQLException ex) {
            Logger.getLogger(Servicios.Dao.Impl.CotizacionDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return max;
    
    }
    
    
}
